package main

import (
	"fmt"
	"net"
	"manyuser/common/message"
	"manyuser/server/utils"
	"manyuser/server/process"
)
type Processor struct{
	Conn net.Conn
}
//处理不同消息类型
func (this *Processor)ServerProcessMes(mes *message.Message)(err error){
	switch mes.Type{
	case message.LoginMesType:
		err=(&process.UserProcess{Conn:this.Conn,}).ServerProcessLogin(mes)
	case message.RegisterMesType:
		err=(&process.UserProcess{Conn:this.Conn,}).ServerProcessRegister(mes)
	case message.SmsMesType:
		(&process.SmsProcess{}).SendGroupMes(mes)	
	default:
		fmt.Println(" The message type doesn't exist")
	}
	return
}

//开启协程，
func (this *Processor)Processing()(err error){
	for{
		
		message,err:=(&utils.Transfer{Conn:this.Conn,}).ReadPkg()
		if err!=nil{
			fmt.Println("server conn.readPkg wrong,",err)
			return 	err	
		}else{
			fmt.Println("the data readed is:",message)
			err=this.ServerProcessMes(&message)
			if err!=nil{
				fmt.Println("server serverProcessMes(conn ,message),",err)
				return err
			}
		}


	}
	return
}